import { ITEM_RENDER_EVT } from "element-plus/es/components/virtual-list/src/defaults";
import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  state(): {
    menus: IMenu[],
    username:string
  } {
    return {
      menus: [],
      username: ''
    };
  },
  getters: {
    activemenus(){
      const arr:IActiveMenu[] = this.menus.filter(item => item.parentId === 0);
      this.menus.forEach(item =>{
        const p = arr.find(p => p.id === item.parentId && item.hidden === 0);
        if(p) {
          if(!p.children) {
            p.children  = []
          }
          p.children.push(item)
        }
      })
      return arr
    }
  }
});